/*
 * @(#)BuyServiceImpl.java 2011-11-08
 *
 * Copyright 2011 北龙中网（北京）科技有限责任公司. All rights reserved.
 */
package cn.shangjia.shop.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.shangjia.common.dao.support.Page;
import cn.shangjia.common.domain.BuyOnline;
import cn.shangjia.common.util.StringUtils;
import cn.shangjia.shop.dao.BuyOnlineDao;
import cn.shangjia.shop.exception.NotFoundException;
import cn.shangjia.shop.service.BuyService;

/**
 * 求购服务实现.
 *
 * @author <a href="mailto:wangxin@knet.cn">wangxin</a>
 * @version 1.0, 2011-11-08 20:18:46
 * @since 1.0
 */
@Service
public class BuyServiceImpl implements BuyService {
	
	@Resource
	private BuyOnlineDao buyOnlineDao;

	/*
	 * (non-Javadoc)
	 * @see cn.shangjia.shop.service.BuyService#findBuyPage(java.lang.String, java.lang.String, int, int)
	 */
	@Override
	public Page<BuyOnline> findBuyPage(String userId, String dir, int pageNo,int pageSize) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		if (!StringUtils.isEmpty(dir))
			params.put("dir", dir);
		Page<BuyOnline> page = new Page<BuyOnline>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		page.setAutoCount(false);
		page.setTotalCount(buyOnlineDao.totalCount(params));
		
		return buyOnlineDao.selectListPage(page, params);
	}

	/*
	 * (non-Javadoc)
	 * @see cn.shangjia.shop.service.BuyOnlineService#getBuyById(java.lang.String)
	 */
	@Override
	public BuyOnline getBuyById(String id) {
		if (StringUtils.isEmpty(id))
			throw new NotFoundException();
		return buyOnlineDao.read(id);
	}
	
}
